#include "mainwindow.h"

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
{
    initView();
}

void MainWindow::initView()
{

   initSessionManageTreeView();
    initShellWidget();

    initMenuBar();
    initToolBar();

    initMainWindow();

}
void MainWindow::initMainWindow()
{


    QDesktopWidget *deskdop = QApplication::desktop();
    // 设置窗口初始化大小
    //resize(1080,2920);
    qDebug()<<"height:"<<deskdop->height();
    qDebug()<<"width:" <<deskdop->width();
    // 设置窗口初始化展示位置
    move((deskdop->width() - this->width())/2, (deskdop->height() - this->height())/2);

    // 窗口布局
    setDockNestingEnabled(true);
    addDockWidget(Qt::DockWidgetArea::LeftDockWidgetArea,m_seeionTreeView);
    splitDockWidget(m_seeionTreeView,m_shellDockwidget,Qt::Horizontal);

}

void MainWindow::initMenuBar()
{
    m_mainMenuBar = new QMenuBar(this);   //
     initFileMenu();
     initEditMenu();
     initViewMenu();
     initOptionMenu();
     initWindowMenu();
     initHelpMenu();
}

void MainWindow::initFileMenu()
{
    // 文件按钮相关操作
    m_fileMenu = menuBar()->addMenu(tr("&file"));
    m_fileMenu->setMinimumWidth(MENUBAR_WIDTH);

    m_connetAction = new QAction(QIcon(":/icon/connect.svg"),tr("connect"),m_fileMenu);
    m_quickConnectAction = new QAction(QIcon(":/icon/quickconnect.svg"),tr("quick connect"),m_fileMenu);
    m_reconnetAction = new QAction(QIcon(":/icon/reconnect.svg"),tr("Reconnect"),m_fileMenu);
    m_disconnetAction = new QAction(QIcon(":/icon/disconnect.svg"),tr("Disconnect"),m_fileMenu);
    m_cloneSessionAction = new QAction(tr("clone session"),m_fileMenu);;
    m_connectSftpSessionAction = new QAction(tr("connect sftp session"),m_fileMenu);
    m_exitAction = new QAction(tr("Exit"),m_fileMenu);

    m_fileMenu->addAction(m_connetAction);
    m_fileMenu->addAction(m_quickConnectAction);
    m_fileMenu->addSeparator();
    m_fileMenu->addAction(m_reconnetAction);
    m_fileMenu->addAction(m_disconnetAction);
    m_fileMenu->addAction(m_cloneSessionAction);
    m_fileMenu->addAction(m_connectSftpSessionAction);
    m_fileMenu->addSeparator();
    m_fileMenu->addAction(m_exitAction);


}

void MainWindow::initEditMenu()
{
    // 编辑相关操作
    m_editMenu = menuBar()->addMenu(tr("&edit"));
    m_editMenu->setMinimumWidth(MENUBAR_WIDTH);

    m_copyAction= new QAction(tr("Copy"),m_editMenu);
    m_pasteAction= new QAction(tr("Paste"),m_editMenu);
    m_copyAndPasteAction= new QAction(tr("Copy and Paste"),m_editMenu);
    m_clearScreenAction= new QAction(tr("Clear Screen"),m_editMenu);
    m_clearScollbackAction= new QAction(tr("Clear Scollback"),m_editMenu);
    m_resetAction= new QAction(tr("Reset"),m_editMenu);

    m_editMenu->addAction(m_copyAction);
    m_editMenu->addAction(m_pasteAction);
    m_editMenu->addAction(m_copyAndPasteAction);
    m_editMenu->addSeparator();
    m_editMenu->addAction(m_clearScreenAction);
    m_editMenu->addAction(m_clearScollbackAction);
    m_editMenu->addSeparator();
    m_editMenu->addAction(m_resetAction);
}

void MainWindow::initViewMenu()
{
    m_viewMenu = menuBar()->addMenu(tr("&view"));

    m_menuBarViewAction = new QAction(tr("menuBar"),m_viewMenu);
    m_toolBarViewAction = new QAction(tr("toolBar"),m_viewMenu);
    m_sessionTabsViewAction = new QAction(tr("sessionTabs"),m_viewMenu);
    m_commandWindowViewAction = new QAction(tr("commandWindow"),m_viewMenu);
    m_statusBarViewAction = new QAction(tr("statusBar"),m_viewMenu);
    m_sessionManagerViewAction = new QAction(tr("sessionManager"),m_viewMenu);
    m_sessionManagerViewAction->setCheckable(true);
    m_sessionManagerViewAction->setChecked(true);
    m_zoomViewAction = new QAction(tr("zoomView"),m_viewMenu);

    m_viewMenu->addAction(m_menuBarViewAction);
    m_viewMenu->addAction(m_toolBarViewAction);
    m_viewMenu->addAction(m_sessionTabsViewAction);
    m_viewMenu->addAction(m_commandWindowViewAction);
    m_viewMenu->addAction(m_statusBarViewAction);
    m_viewMenu->addAction(m_sessionManagerViewAction);
    m_viewMenu->addAction(m_zoomViewAction);
    connect(m_sessionManagerViewAction,SIGNAL(triggered()),this,SLOT(slotSessionManagerViewAction()));
}

void MainWindow::initOptionMenu()
{
    m_optionMenu = menuBar()->addMenu(tr("&option"));

    m_sessionOptionsAction = new QAction(tr("session option"),m_optionMenu);
    m_EditDefaultSessionOptionsAction = new QAction(tr("edit default session"),m_optionMenu);
    m_GlableOptionsAction = new QAction(tr("glable options"),m_optionMenu);
    m_AutoSaveOptionsAction = new QAction(tr("auto save options"),m_optionMenu);

    m_optionMenu->addAction(m_sessionOptionsAction);
    m_optionMenu->addAction(m_EditDefaultSessionOptionsAction);
    m_optionMenu->addAction(m_GlableOptionsAction);
    m_optionMenu->addAction(m_AutoSaveOptionsAction);

}

void MainWindow::initWindowMenu()
{
    m_windowsMenu = menuBar()->addMenu(tr("&windows"));
}

void MainWindow::initHelpMenu()
{
    m_helpMenu = menuBar()->addMenu(tr("&help"));

    m_updateNowHelpAction = new QAction(tr("update now"),m_helpMenu);
    m_checkForUpdateHelpAction = new QAction(tr("check for update"),m_helpMenu);
    m_aboutHelpAction = new QAction(tr("about"),m_helpMenu);

    m_helpMenu->addAction(m_updateNowHelpAction);
    m_helpMenu->addAction(m_checkForUpdateHelpAction);
    m_helpMenu->addAction(m_aboutHelpAction);

   connect(m_aboutHelpAction,SIGNAL(triggered()),this,SLOT(slotShowAboutDialog()));
}

void MainWindow::initToolBar()
{
    m_toolBar = addToolBar("file");
    m_actionConnect = new QAction(QIcon(":/icon/connect.svg"),"connect");
    m_actionDisonnect = new QAction(QIcon(":/icon/disconnect.svg"),"disconnect");
    m_actionReonnect = new QAction(QIcon(":/icon/reconnect.svg"),"reconnect");
    m_actionCopy = new QAction(QIcon(":/icon/copy.svg"),"copy");
    m_actionPaste = new QAction(QIcon(":/icon/paste.svg"),"copy");
    m_toolBar->addAction(m_actionConnect);
    m_toolBar->addAction(m_actionDisonnect);
    m_toolBar->addAction(m_actionReonnect);
    m_toolBar->addSeparator();
    m_toolBar->addAction(m_actionCopy);
    m_toolBar->addAction(m_actionPaste);
     /*this->addToolBar(toolBar);*/
}

void MainWindow::initSessionManageTreeView()
{
    //右窗口1
       m_seeionTreeView=new sessionManageTreeView(this);
       m_seeionTreeView->setFeatures(QDockWidget::DockWidgetFloatable);
       m_seeionTreeView->setAllowedAreas(Qt::LeftDockWidgetArea);

}

void MainWindow::initShellWidget()
{
    m_shellDockwidget = new CShellDockWidget(this);
    m_shellDockwidget->setFeatures(QDockWidget::DockWidgetFloatable);
    m_shellDockwidget->setAllowedAreas(Qt::RightDockWidgetArea);
}




void MainWindow::showAboutDialog()
{
    AboutDialog a;
    a.exec();
}

void MainWindow::onStatusBarViewAction()
{

}

void MainWindow::onConnetAction()
{

}

void MainWindow::onQuickConnectAction()
{

}

void MainWindow::onReconnetAction()
{

}

void MainWindow::onDisconnetAction()
{

}

void MainWindow::onCloneSessionAction()
{

}

void MainWindow::onConnectSftpSessionAction()
{

}

void MainWindow::onExitAction()
{

}

void MainWindow::onCopyAction()
{

}

void MainWindow::onPasteAction()
{

}

void MainWindow::onCopyAndPasteAction()
{

}

void MainWindow::onClearScreenAction()
{

}

void MainWindow::onClearScollbackAction()
{

}

void MainWindow::onResetAction()
{

}

void MainWindow::onMenuBarViewAction()
{

}

void MainWindow::onToolBarViewAction()
{

}

void MainWindow::onSessionTabsViewAction()
{

}

void MainWindow::onCommandWindowViewAction()
{

}

void MainWindow::onSessionManagerViewAction()
{
    if(m_seeionTreeView->isHidden())
    {
        m_seeionTreeView->show();
    }
    else {
        m_seeionTreeView->hide();
    }
}

void MainWindow::onZoomViewAction()
{

}

void MainWindow::onSessionOptionsAction()
{

}

void MainWindow::onEditDefaultSessionOptionsAction()
{

}

void MainWindow::onGlableOptionsAction()
{

}

void MainWindow::onAutoSaveOptionsAction()
{

}

void MainWindow::onUpdateNowHelpAction()
{

}

void MainWindow::onCheckForUpdateHelpAction()
{

}

void MainWindow::slotShowAboutDialog()
{
    showAboutDialog();
}

void MainWindow::slotStatusBarViewAction()
{

}

void MainWindow::slotConnetAction()
{

}

void MainWindow::slotQuickConnectAction()
{

}

void MainWindow::slotReconnetAction()
{

}

void MainWindow::slotDisconnetAction()
{

}

void MainWindow::slotCloneSessionAction()
{

}

void MainWindow::slotConnectSftpSessionAction()
{

}

void MainWindow::slotExitAction()
{

}

void MainWindow::slotCopyAction()
{

}

void MainWindow::slotPasteAction()
{

}

void MainWindow::slotCopyAndPasteAction()
{

}

void MainWindow::slotClearScreenAction()
{

}

void MainWindow::slotClearScollbackAction()
{

}

void MainWindow::slotResetAction()
{

}

void MainWindow::slotMenuBarViewAction()
{

}

void MainWindow::slotToolBarViewAction()
{

}

void MainWindow::slotSessionTabsViewAction()
{

}

void MainWindow::slotCommandWindowViewAction()
{

}

void MainWindow::slotSessionManagerViewAction()
{
    onSessionManagerViewAction();
}

void MainWindow::slotZoomViewAction()
{

}

void MainWindow::slotSessionOptionsAction()
{

}

void MainWindow::slotEditDefaultSessionOptionsAction()
{

}

void MainWindow::slotGlableOptionsAction()
{

}

void MainWindow::slotAutoSaveOptionsAction()
{

}
// 帮互赞秀改
void MainWindow::slotUpdateNowHelpAction()
{

}

void MainWindow::slotCheckForUpdateHelpAction()
{

}

MainWindow::~MainWindow()
{
    // 关于我们
    SAFE_DELETE_ELE(m_seeionTreeView);      // 树形结构的绘画管理
    SAFE_DELETE_ELE(m_shellDockwidget);

    SAFE_DELETE_ELE(m_actionConnect);                     // 快速链接操作
    SAFE_DELETE_ELE(m_actionDisonnect);                   // 断开链接操作
    SAFE_DELETE_ELE(m_actionReonnect);                    // 重新链接操作
    SAFE_DELETE_ELE(m_actionCopy);                        // 复制链接操作
    SAFE_DELETE_ELE(m_actionPaste);                       // 粘贴浍话操作

    // 工具栏
    SAFE_DELETE_ELE(m_toolBar);
    // QAction *openFileAction;
    SAFE_DELETE_ELE(m_connetAction);                // 文件 -> 链接
    SAFE_DELETE_ELE(m_quickConnectAction);          // 文件 -> 快速链接
    SAFE_DELETE_ELE(m_reconnetAction);              // 文件 -> 再次链接
    SAFE_DELETE_ELE(m_disconnetAction);             // 文件 -> 再次链接
    SAFE_DELETE_ELE(m_cloneSessionAction);          // 文件 -> 克隆链接
    SAFE_DELETE_ELE(m_connectSftpSessionAction);    // 文件 -> 以sftp链接
    SAFE_DELETE_ELE(m_exitAction);                  // 程序退出

    // 编辑相关
    SAFE_DELETE_ELE(m_copyAction);                  // 复制
    SAFE_DELETE_ELE(m_pasteAction);                 // 粘贴
    SAFE_DELETE_ELE(m_copyAndPasteAction);          // 复制并且粘贴
    SAFE_DELETE_ELE(m_clearScreenAction);           // 清理回话
    SAFE_DELETE_ELE(m_clearScollbackAction);        // 清理屏幕
    SAFE_DELETE_ELE(m_resetAction);

    // 视图相关
    SAFE_DELETE_ELE(m_menuBarViewAction);               // 菜单栏
    SAFE_DELETE_ELE(m_toolBarViewAction);               // 工具兰
    SAFE_DELETE_ELE(m_sessionTabsViewAction);           //
    SAFE_DELETE_ELE(m_commandWindowViewAction);         // 命令窗口
    SAFE_DELETE_ELE(m_statusBarViewAction);             // 状态栏
    SAFE_DELETE_ELE(m_sessionManagerViewAction);        //
    SAFE_DELETE_ELE(m_zoomViewAction);                  // 放大或者缩小

    // 操作相关
    SAFE_DELETE_ELE(m_sessionOptionsAction);
    SAFE_DELETE_ELE(m_EditDefaultSessionOptionsAction);
    SAFE_DELETE_ELE(m_GlableOptionsAction);
    SAFE_DELETE_ELE(m_AutoSaveOptionsAction);

    // 帮助
    SAFE_DELETE_ELE(m_updateNowHelpAction);               // 升级
    SAFE_DELETE_ELE(m_checkForUpdateHelpAction);          // 检查升级
    SAFE_DELETE_ELE(m_aboutHelpAction);

    SAFE_DELETE_ELE(m_fileMenu);        // 文件菜单
    SAFE_DELETE_ELE(m_editMenu);        // 编辑菜单
    SAFE_DELETE_ELE(m_viewMenu);        // 视图菜单
    SAFE_DELETE_ELE(m_optionMenu);      // 操作菜单
    SAFE_DELETE_ELE(m_windowsMenu);     // 窗口菜单
    SAFE_DELETE_ELE(m_helpMenu);        // 帮助菜单


    SAFE_DELETE_ELE(m_mainMenuBar);
    //SAFE_DELETE_ELE(m_mainLayout);
}
